package com.ruoyi.tcsp.service.impl;

import com.ruoyi.tcsp.service.FileService;
import com.ruoyi.tcsp.utils.MinioUtils;
import com.ruoyi.tcsp.config.MinioConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;


@Component
public class FileServiceImpl implements FileService {
    @Autowired
    private MinioUtils minioUtils;
    @Autowired
    private MinioConfig minioConfig;
    @Override
    public String upload(MultipartFile file) {
        boolean exist = minioUtils.existBucket(minioConfig.getBucketName());
        if (!exist) {
            minioUtils.makeBucket(minioConfig.getBucketName());
        }
        minioUtils.upload(file, file.getOriginalFilename());
        String fileUrl = minioUtils.getFileUrl(file.getOriginalFilename());
        return fileUrl;
    }
}
